<template>
  <div>
    <el-container class="con">
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <el-menu
          class="el-menu-vertical-demo"
          :background-color="$primary2"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
          unique-opened
        >
          <el-menu-item index="/home">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>

          <!-- <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>系统设置</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/caidan">菜单管理</el-menu-item>
              <el-menu-item index="/juese">角色管理</el-menu-item>
              <el-menu-item index="/guanliyuan">管理员管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu> -->

          <!-- 动态侧边 -->
          <div v-for="item in user.menus" :key="item.id">
            <!-- 菜单 -->
            <el-menu-item v-if="!item.children" :index="item.url">{{item.title}}</el-menu-item>
           <!-- 目录 -->
            <el-submenu :index="item.id+''" v-else>
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{item.title}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item v-for="i in item.children" :key="i.id" :index="i.url">{{i.title}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </div>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <el-button type="primary" @click="logout">退出登录</el-button>
          <div>用户：{{user.username}}</div>
        </el-header>
        <el-main>
          <el-breadcrumb
            separator-class="el-icon-arrow-right"
            v-if="$route.meta.title"
          >
            <!-- 面包屑 -->
            <el-breadcrumb-item :to="{ path: '/home' }"
              >首页</el-breadcrumb-item
            >
            <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- 二级路由出口 -->
          <router-view class="bianju"></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
export default {
  props: [],
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      user: "user",
    }),
  },
  mounted() {},
  methods: {
    ...mapActions({
      changeuser: "changeuser",
    }),
    //退出登录
    logout() {
      this.changeuser({});
      this.$router.replace("/login");
    },
  },
};
</script>
<style scoped lang="less">
@import "../../less/index.less";
.element.style {
  background: @primary2;
}
.el-header {
  float: right;
}
.el-header div {
  // display: inline;
  margin-top: 20px;
  float: right;
}
.el-button--primary {
  float: right;
  margin-top: 10px;
}
.el-aside {
  background: @primary2;
}
.el-header {
  background: @header-color;
}
.con {
  height: 100vh;
}
.bianju {
  margin-top: 20px;
}
</style>